<template>
	<view>
		<view v-if="type == 0" class="contain">
			<p>您当前身份为“企业”</p>
			<view class="btn"><u-button @click="setNnterprises(choice)" type="primary" size="large"><span style="color: white;font-weight: 700;">切换为“个人”身份</span></u-button></view>
			<view class="btn" style="margin-top: 30rpx;"><u-button @click="goback()" color="#f4f4f5"  size="large"><span style="color: black;font-weight: 450;">返回</span></u-button></view>
		</view>
		<view v-if="type == 1" class="contain" style="margin: 200rpx auto;">
			<p>选择身份进入</p>
			<view v-for="(nvitem,nvindex) in Nnterprises" :key="nvindex"
					class="choose" @click="checkItem(nvitem,nvindex)">
					{{nvitem.itemName}}
			</view>
			<view class="btn" style="margin-top: 30rpx;"><u-button @click="goback()" color="#f4f4f5"  size="large"><span style="color: black;font-weight: 450;">返回</span></u-button></view>
		</view>
	</view>
</template>

<script>
	import Index from '@/common/index-model.js'
	let index = new Index();
	let that = null;
	export default {
		data() {
			return {
				type:'',
				Nnterprises:'',
				choice:{itemId:0},
				ischicked :true
			}
		},
		onLoad(opt) {
			this.type = opt.type
			this.getSwitchNnterprises()
		},
		methods: {
			goback(){
				index.navigate_back()
			},
			getSwitchNnterprises() {
				index.getPublicUserMember({}, 'client/individual/switchIdentityList', 'get', res => {
					if (res.data.code == 200 && res.data.success) {
						this.Nnterprises = res.data.result
					}
				})
			},
			checkItem(item, index) {
				if(!this.ischicked) return
					this.ischicked = false
					this.currindex = index
					console.log(this.currindex,item)
					this.setNnterprises(item)
			},
			setNnterprises(item) {
				let url = 'client/individual/switchIdentity/' + item.itemId
				index.getPublicUserMember({}, url, 'post', res => {
					if (res.data.code == 200 && res.data.success) {
							if(this.type == 0){
								index.navigate_back()
							}
							if(this.type == 1){
								uni.redirectTo({
									url: "/pagesC/job/issuejob?entid="+ item.itemId
								})
								// this.ischicked = true;
							}
					} else {
						// this.ischicked = true;
						index.show_tips(res.data.message)
						return false
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.contain {
		margin: 500rpx auto;

		p {
			text-align: center;
			margin-bottom: 60rpx;
			font-size: 50rpx;
			font-weight: bold;
		}
		.btn{
			width: 70%;
			margin:  0 auto;
		}
		.choose{
			display: flex;
			justify-content: center;
			width: 80%;
			margin: 20rpx auto;
			background-color: #3c9cff;
			color: white;
			font-weight: 600;
			padding: 20rpx;
			border-radius: 20rpx;
		}
	}
</style>